<?php
// +----------------------------------------------------------------------
// | RXThinkCMF_EVTP5.1_PRO前后端分离旗舰版框架 [ RXThinkCMF ]
// +----------------------------------------------------------------------
// | 版权所有 2018~2021 南京RXThinkCMF研发中心
// +----------------------------------------------------------------------
// | 官方网站: http://www.rxthink.cn
// +----------------------------------------------------------------------
// | 作者: ZhangXuanNeng <rxthinkcmf@163.com>
// +----------------------------------------------------------------------
// | 免责声明:
// | 本软件框架禁止任何单位和个人用于任何违法、侵害他人合法利益等恶意的行为，禁止用于任何违
// | 反我国法律法规的一切平台研发，任何单位和个人使用本软件框架用于产品研发而产生的任何意外
// | 、疏忽、合约毁坏、诽谤、版权或知识产权侵犯及其造成的损失 (包括但不限于直接、间接、附带
// | 或衍生的损失等)，本团队不承担任何法律责任。本软件框架只能用于公司和个人内部的法律所允
// | 许的合法合规的软件产品研发，详细声明内容请阅读《框架免责声明》附件；
// +----------------------------------------------------------------------

namespace app\admin\service;

use app\admin\model\Member;

/**
 * 会员管理-服务类
 * @author ZhangXuanNeng
 * @since 2020/11/20
 * Class MemberService
 * @package app\admin\service
 */
class MemberService extends BaseService
{
    /**
     * 构造函数
     * @author ZhangXuanNeng
     * @since 2020/11/20
     * MemberService constructor.
     */
    public function __construct()
    {
        $this->model = new Member();
    }

    /**
     * 获取数据列表
     * @return array
     */
    public function getList()
    {
        $param = request()->param();

        // 查询条件
        $map = [];
        if(isset($param['game_id']) && !empty($param['game_id'])){
            $map[] = ['game_id','=',$param['game_id']];
        }
        if(isset($param['promote_id']) && !empty($param['promote_id'])){
            $map[] = ['promote_id','=',$param['promote_id']];
        }
        if(isset($param['phone']) && !empty($param['phone'])){
            $map[] = ['phone','=',$param['phone']];
        }
        if(isset($param['username']) && !empty($param['username'])){
            $map[] = ['username','=',$param['username']];
        }
        if(isset($param['id']) && !empty($param['id'])){
            $map[] = ['id','=',$param['id']];
        }
        if(isset($param['pid']) && !empty($param['pid'])){
            $map[] = ['pid','=',$param['pid']];
        }
        if(isset($param['create_time']) && !empty($param['create_time'])){
            $map[] = ['create_time','between time',$param['create_time']];
        }
        if(isset($param['user_type'])){
            if($param['user_type'] == 1){
                $map[] = ['pid','=',0];
            }
            if($param['user_type'] == 2){
                $map[] = ['pid','>',0];
            }
        }
        $res = parent::getListNewNoCache($map, "id desc");
        foreach ($res['data'] as $k=>&$v){
            $v['username'] = get_substr_replace($v['username']);
            $v['phone'] = get_substr_replace($v['phone']);
        }
        return $res;
    }

    /**
     * 添加或编辑
     * @return mixed
     * @since 2020/11/20
     * @author ZhangXuanNeng
     */
    public function edit()
    {
        // 请求参数
        $data = request()->param();
        // 头像处理
//        $avatar = getter($data, 'avatar');
//        if (strpos($avatar, "temp")) {
//            $data['avatar'] = save_image($avatar, 'member');
//        } else {
//            $data['avatar'] = str_replace(IMG_URL, "", $data['avatar']);
//        }
//
//        // 出生日期
//        if ($data['birthday']) {
//            $data['birthday'] = strtotime($data['birthday']);
//        }

        if($data['password']){
            $data['password'] = setMd5Pwd($data['password']);
        }else{
            unset($data['password']);
        }
        return parent::edit($data); // TODO: Change the autogenerated stub
    }

    /**
     * 推广员换绑信息获取
     * @return array
     */
    public function getMemberGamePromoteInfo()
    {
        $param = request()->param();
        $row = $this->model->getMemberGamePromoteInfo($param['member_id']);
        return $row;
    }
    // 获取玩家游戏推广员
    public function getMemberGamePromote(){
        $param = request()->param();
        $row = $this->model->getMemberGamePromote($param['member_id'],$param['game_id']);
        return $row;
    }
    // 更新玩家游戏推广员
    public function setMemberGamePromote(){
        $param = request()->param();
        $row = $this->model->setMemberGamePromote($param);
        return $row;
    }
    // 批量更新玩家游戏推广员
    public function setMemberGamePromoteBatch(){
        $param = request()->param();
        $row = $this->model->setMemberGamePromoteBatch($param);
        return $row;
    }
    // 换绑小号
    public function setMemberChild(){
        $param = request()->param();
        $row = $this->model->setMemberChild($param);
        return $row;
    }

    // 获取账号信息
    public function getAccount(){
        $param = request()->param();
        $row = $this->model->getAccount($param);
        return $row;
    }
    // 换绑手机
    public function setMemberPhone(){
        $param = request()->param();
        $row = $this->model->setMemberPhone($param);
        return $row;
    }
}
